export const handleTableScroll = (threshold = 300) => {
	const appContainer = document.querySelector('.el-card');
	const tableContainer = document.querySelector('.el-table');
	const tableBody = document.querySelector('.el-table__body');
	const headerWrapper = document.querySelector('.el-table__header-wrapper');
	const fixedLeftHeaderWrapper = document.querySelector('.el-table__fixed-header-wrapper');
	const fixedLeftTable = document.querySelector('.el-table__fixed');
	// 容器顶部位置
	const appContainerTop = appContainer.getBoundingClientRect().top + 1;
	// 当前滚动距离
	const scrollTop = appContainer.scrollTop;
	// 表格容器宽度
	const tableContainerWidth = tableContainer.getBoundingClientRect().width - 4;
	// 表格主体高度
	const tableHeight = tableBody.getBoundingClientRect().height;
	// 属性容器高度
	const headerWrapperHeight = headerWrapper.getBoundingClientRect().height;
	// 左边固定表格宽度
	const fixedLeftTableWidth = fixedLeftTable?.getBoundingClientRect().width;
	// 左边固定表格位置
	const fixedLeftTableLeft = fixedLeftTable?.getBoundingClientRect().left;
	if (scrollTop >= threshold) {
		// 处理非固定列的属性
		headerWrapper.style.position = "fixed";
		headerWrapper.style.zIndex = "9";
		headerWrapper.style.top = appContainerTop + "px";
		headerWrapper.style.width = tableContainerWidth + "px";

		// 处理左边固定区域
		if (fixedLeftHeaderWrapper) {
			// 处理固定列的属性
			fixedLeftHeaderWrapper.style.position = "fixed";
			fixedLeftHeaderWrapper.style.zIndex = "10";
			fixedLeftHeaderWrapper.style.left = fixedLeftTableLeft + "px";
			fixedLeftHeaderWrapper.style.top = appContainerTop + "px";
			fixedLeftHeaderWrapper.style.width = fixedLeftTableWidth + "px";
			fixedLeftHeaderWrapper.style.overflow = "hidden";

			// 处理固定表格区域
			fixedLeftTable.style.top = (-headerWrapperHeight) + "px";
			fixedLeftTable.style.height = (tableHeight + headerWrapperHeight) + 'px';
		}
	} else {
		// 还原非固定列属性
		headerWrapper.style.position = "";
		headerWrapper.style.zIndex = "";
		headerWrapper.style.top = "";
		headerWrapper.style.width = "";

		// 还原左边固定区域
		if (fixedLeftHeaderWrapper) {
			// 还原固定列的属性
			fixedLeftHeaderWrapper.style.position = "";
			fixedLeftHeaderWrapper.style.zIndex = "";
			fixedLeftHeaderWrapper.style.left = "";
			fixedLeftHeaderWrapper.style.top = "";
			fixedLeftHeaderWrapper.style.width = "";
			fixedLeftHeaderWrapper.style.overflow = "";

			// 还原固定表格区域
			fixedLeftTable.style.top = "";
			fixedLeftTable.style.height = tableHeight + "px";
		}
	}
}